package bman.filecopy;

import junit.framework.TestCase;

public class SplitFileNamesTest extends TestCase
{
	public void testWithOneFileName()
	{
		String cmd = "file1.txt";
		String[] s = FileSys.splitFileNames(cmd);
		assertEquals(cmd,s[0]);
	}
	
	public void testOneFileNameWithSpaces()
	{
		System.out.println("\n\nTesting one file name with spaces...");
		
		String cmd2 = "file with spaces.txt";
		
		/*
		 * add qoutes first
		 */
		String cmdQ = "\""+cmd2+"\"";
		System.out.println("The file: "+cmdQ);
		
		String[] result2 = FileSys.splitFileNames(cmdQ);
		System.out.println("The result: "+result2[0]);
		assertEquals(cmd2,result2[0]);
		System.out.println("\n\n");
	}
	
	public void testSplictFileNames1()
	{
		/*
		 * The expected file names 
		 */
		String[] expected = {
				"file1.txt", 
				"file2.txt", 
				"\"yumy yumy.txt\"",
				"another.file",
				"\"another space file.txt\"",
				"\"1 2 3 4 5 6 7 . ext\"",
				};
		
		/*
		 * Build the file name into one string separated by a space.
		 */
		String cmd = "";
		
		for(String s: expected)
		{
			cmd += s+" ";
		}
		System.out.println("Files to split: "+cmd);
		
		/*
		 * Now call the method that needs to be tested (FileSys.splitFileNames)
		 */
		String[] actualArray = FileSys.splitFileNames(cmd);
		System.out.println("\n\nsplitFileName result: ");
		for(int i = 0; i < actualArray.length ;i++)
		{
			System.out.println(i+": "+actualArray[i]);
		}
		
		/*
		 * Check the results
		 */
		System.out.println("\n\nPerforming matches...\n\n");
		
		assertEquals(expected.length,actualArray.length);
	}

}
